-------------------------------------------------------------------------
-- Get Player's Main Talent in String
-------------------------------------------------------------------------
function trashmobs_GetUnitMainTalentID()
	local talentTabNum=GetNumTalentTabs();
	local talentTreeInfo={};
	local deepestTalent={["COUNT"]=-1, ["INDEX"]=-1};
	for i=1, talentTabNum, 1 do
		talentTreeInfo[i]=0;
		for j=1, GetNumTalents(i) do
			local nameTalent, icon, tier, column, currRank, maxRank = GetTalentInfo(i,j);
			talentTreeInfo[i] = talentTreeInfo[i] + currRank;
		end
		if(talentTreeInfo[i] > deepestTalent["COUNT"]) then
			deepestTalent["COUNT"]=talentTreeInfo[i];
			deepestTalent["INDEX"] =i;
		end
	end
	
	local TalentID=trashmobs_GetENClass(TRM_CLASS) .. "-" ..deepestTalent["INDEX"];
	return TalentID;
end;

-------------------------------------------------------------------------
-- Get Player's Talents in String
-------------------------------------------------------------------------
function trashmobs_GetUnitTalents()
	local talentTabNum=GetNumTalentTabs();
	local talentTreeInfo={};
	
	for i=1, talentTabNum, 1 do
		talentTreeInfo[i]=0;
		for j=1, GetNumTalents(i) do
			local nameTalent, icon, tier, column, currRank, maxRank = GetTalentInfo(i,j);
			talentTreeInfo[i] = talentTreeInfo[i] + currRank;
		end
	end
	
	local talentString="";
	for i=1, talentTabNum, 1 do
		talentString= talentString .. talentTreeInfo[i];
		if(i < talentTabNum) then
			talentString = talentString .. "/";
		end
	end
	return talentString;
end;


------------------------------------------------------------------------------------
-- get Player'Role in Text (Tank,Healer,DD)
-----------------------------------------------------------------------------------
function trashmobs_GetUnitRoleID()
	local playerTalentID=trashmobs_GetUnitMainTalentID();
	local playerTalent=trashmobs_GetTalentNameByID(playerTalentID);
	
	if ((playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_WARRIOR][3]) 
		or (playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_DRUID][2])  
		or (playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_PALADIN][2])) then
		return 1;
	elseif ((playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_PRIEST][1]) 
		or(playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_PRIEST][2])
		or(playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_DRUID][3])
		or(playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_SHAMAN][3])
		or(playerTalent == TRASHMOBS_TALENT_NAME[TRASHMOBS_PALADIN][1])) then
		return 2;
	else
		return 3;
	end

end;

----------------------------------------------------------------------------------
-- Get Localizised Talent Name from "Warrior-1";
-----------------------------------------------------------------------------------
function trashmobs_GetTalentNameByID(talentID)
	local regex="(%a-)%-(%d?)";
	local ENClass, TalentIndex;
	for __ENClass, __TalentIndex in string.gmatch(talentID,regex) do
		ENClass=__ENClass;
		TalentIndex=tonumber(__TalentIndex);
	end

	local LocalClass="";
	
	for u,v in pairs(TRM_EN_CLASS_NAMES) do
		if(v== ENClass) then
			LocalClass=u;
		end
	end
	
	return TRASHMOBS_TALENT_NAME[LocalClass][TalentIndex];
end;

----------------------------------------------------------------------
-- get internal Class Name from English Class Name
----------------------------------------------------------------------
function trashmobs_GetInternalClass(ENClass)
	for i,j in pairs(TRM_EN_CLASS_NAMES) do
		if(string.upper(j)==ENClass) then
			return i;
		end
	end
	
	return nil;
end;

----------------------------------------------------------------------
--get English Classname from localized Class Name
----------------------------------------------------------------------
function trashmobs_GetENClass(localClass)
	local classIndex=trashmobs_TableGetItem(TRM_DATA_STRINGS["CLASSES"], localClass);
	if(classIndex <0) then
		return nil;	--not found
	end
	
	for i,j in pairs(TRM_EN_CLASS_RELATION) do
		for k=1, #j do
			if (j[k]==classIndex) then
				return TRM_EN_CLASS_NAMES[i];
			end
		end
	end
	
	return nil;	-- not found
end;

----------------------------------------------------------------------
--get man Classname from localized Class Name
----------------------------------------------------------------------
function trashmobs_GetManClass(localClass)
	local classIndex=trashmobs_TableGetItem(TRM_DATA_STRINGS["CLASSES"], localClass);
	if(classIndex <0) then
		return nil;	--not found
	end
	
	for i,j in pairs(TRM_EN_CLASS_RELATION) do
		for k=1, #j do
			if (j[k]==classIndex) then
				return i;
			end
		end
	end
	
	return nil;	-- not found
end;
